<script>
// import plusListener from '@/utils/unipushListener.js'
import common from '@/pages/common/common.js'

export default {
  mixins: [common],
  globalData: {
    config: {
      logo: "",
      app_name: "",
      rtsp_url: "", // 视频流地址
      ps_url: "", // 硬盘录像机地址
    },
    videoAuth: false, // 监控视频权限
    tabbarMidButton: true, // tabbar 中间是否凸起
    isGuard: false, // 智能分析权限
    list: [
      {
        pagePath: "/pages/alarmConfirm/index",
        iconPath: "/static/image/alarm_confirm_icon.svg",
        selectedIconPath: "/static/image/alarm_confirm_selected_icon.svg",
        count: 0,
        text: "实时报警",
      },
      {
        pagePath: "/pages/alarm/index",
        iconPath: "/static/image/warning_info_icon.svg",
        selectedIconPath: "/static/image/warning_info_selected_icon.svg",
        text: "预警/报警",
      },
      {
        pagePath: "/pages/workbench/index",
        iconPath: "/static/image/staging_icon.svg",
        selectedIconPath: "/static/image/staging_selected_icon.svg",
        text: "工作台",
        midButton: true,
      },
      {
        pagePath: "/pages/monitoring/index",
        iconPath: "/static/image/workbench_icon.svg",
        selectedIconPath: "/static/image/workbench_selected_icon.svg",
        text: "监测监控",
      },
      {
        pagePath: "/pages/my/index",
        iconPath: "/static/image/personal_center_icon.svg",
        selectedIconPath: "/static/image/personal_center_selected_icon.svg",
        text: "个人中心",
      },
    ],
    token: "",
    userInfo: {},
    userInfoData: {},
    loginTimer: null,
    VIDEO_URL: "http://172.26.0.32:18686/camera-service/camera/getRtspUrl?cameraUuid=",
    coalList: [], // 煤矿列表，避免多次请求
  },
  methods: {
    /**
     * 免登录校验
     */
    verifyLogin () {
      const username = uni.getStorageSync("HCuname");
      const password = uni.getStorageSync("HCpassw");
      if (username && password) {
        this.$post("/login", {
          username,
          password,
          captcha: "test",
          jsessionid: "a250a4bdaecb223da25d4168b9678a9f",
          scLogin: "mobile",
        })
          .then((res) => {
            if (res?.body?.token) {
              // 登录成功
              this.globalData.token = res.body.token;

              // 获取权限
              this.getPrimission();

              // 调整首页
              uni.switchTab({
                url: "/pages/alarmConfirm/index",
                complete: () => {
                  setTimeout(() => {
                    this.closeSplashscreen();
                  }, 300);
                },
              });
            } else {
              this.closeSplashscreen();
            }
          })
          .catch((err) => {
            this.closeSplashscreen();
          });
      } else {
        this.closeSplashscreen();
      }
    },
    /**
     * 关闭启动页面
     */
    closeSplashscreen () {
      // #ifndef H5
      plus.navigator.closeSplashscreen();
      // #endif
    },
  },
  onLaunch: function () {
    // 获取配置信息
    this.getAppConfig({ source: "App" })
      .then((res) => {
        this.verifyLogin();
      })
      .catch(() => {
        this.closeSplashscreen();
      });

    // #ifndef H5
    // 监听推送点击事件
    // plusListener.pushListener()
    // #endif
    // plusListener.startMonitoringNetWork()
  }
}
</script>

<style lang="scss">
@import "uview-ui/index.scss";

/*每个页面公共css */
page {
  height: 100%;
  font-size: 28rpx;
}
.titleNview-placing {
  height: var(--status-bar-height);
  padding-top: 44px;
  box-sizing: content-box;
}
</style>
